package ext;

import org.junit.Test;

import util.ListNode;

public class ReverseTwo {
    
    //两个一组进行反转
    public ListNode reverse(ListNode head) {
        ListNode res = new ListNode(0), result = res, cur = head;
        res.next = head;
        while (cur != null && cur.next != null) {
            ListNode next = cur.next;
            cur.next = next.next;
            next.next = cur;
            res.next = next;
            res = cur;
            cur = cur.next;
        }
        return result.next;
    }


    @Test
    public void test() {
        int[] nums = new int[]{1,2,3,4,5,6};
        System.out.println(reverse(ListNode.newListNodeFromArray(nums)));
    }

}
